'''
Created on 19 dec. 2011

@author: Daan
'''
import math

from Roads.Road import Road

class Straight(Road):
    '''
    classdocs
    '''
    def __init__(self, lanes, x, y, length, opposite, name):
        '''
        Constructor
        '''
        Road.__init__(self, lanes, x, y, length, opposite, name)
 
    def GetX(self):
        return self._x
    
    def GetY(self):
        return self._y
    
    def GetL(self):
        return self._l
    
    def GetXYInLane(self, lane, offset, canvas=None):
        y = self.GetLaneCenter(lane, offset)
        
        x = self._x + offset if self._opposite else (self._x + self._l) - offset
        return (x, y)
    
    def GetLaneCenter(self, lane, offset):
        base = math.ceil(Road.width / 2)
        lane = self._lanes - (lane - 1) if self._opposite else lane
        return self._y + ((lane * Road.width) - base)
    
    def Draw(self, canvas):
        width = self._y + (Road.width * self._lanes)
        canvas.create_rectangle((self._x, self._y, self._x + self._l, width), fill="gray", outline="")
            
        lines = self._lanes + 1
        line = 0
        while line < lines :
            y = self._y + (line * Road.width)
            x = self._x
            l = self._x + self._l
                
            canvas.create_line(x, y, l, y, fill="red")
            
            line += 1
        
